package uestc.lj.basic.greedy;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;

/**
 * 以最小的字典序返回字符数组中字符串顺序
 *
 * @Author:Crazlee
 * @Date:2021/11/24
 */
public class Code02_LowestLexicography {
	public static class MyComparator implements Comparator<String> {
		@Override
		public int compare(String o1, String o2) {
			return (o1 + o2).compareTo(o2 + o1);
		}
	}

	public static String lowestString(String[] strs) {
		if (strs == null || strs.length == 0) {
			return "";
		}
		Arrays.sort(strs, new MyComparator());
		StringBuilder res = new StringBuilder();
		for (String str : strs) {
			res.append(str);
		}
		return res.toString();
	}
}
